using System.Diagnostics.Contracts;
using System.Security.Cryptography.X509Certificates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sundstrom.Mvvm.Messaging;
using Sundstrom.Mvvm.Tests.ViewModels;

namespace Sundstrom.Mvvm.Tests
{
    [TestClass]
    public class MessageBusTests
    {
        [TestMethod]
        public void SendAndReceive_WhiteBoxTest_AssertSenderIsSet()
        {
            var messenger = MessageBus.Default;

            Message m = null;

            messenger.Subscribe<TextMessage>((message) =>
                {
                    m = message;
                });

            messenger.Send(this, new TextMessage("Hello"));

            Contract.Assume(m != null);
            
            Assert.IsNotNull(m);
            Assert.IsNotNull(m.Sender);
            Assert.AreEqual(m.Sender, this);
        }

        [TestMethod]
        public void SendAndReceive_BlackBoxTest_CrossViewModels()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            Assert.IsTrue(string.IsNullOrEmpty(vm2.SampleProperty));

            vm1.SampleProperty2 = "Hello";

            Assert.IsTrue(vm2.SampleProperty == "Hello");
        }
    }
}